package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.GroupDAO;
import com.zerosky.crm.po.Group;
import com.zerosky.crm.service.GroupService;
import com.zerosky.crm.util.PageInfo;

@Service(value = "groupService")
public class GroupServiceImpl implements GroupService {

	@Autowired
	private GroupDAO GroupDao;

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Group> getGroupAllList(Map map) {
		return GroupDao.getGroupAllList(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Group> getGroupPageInfoList(Map map) {
		int begin = (((int) map.get("page") - 1) * (int) map.get("limit"));
		int pageSize = (int) map.get("limit");
		PageInfo<Group> page = new PageInfo<Group>();
		// 写入数据
		map.put("pageNo", begin);
		map.put("pageSize", pageSize);
		List<Group> list = GroupDao.getGroupAllList(map);
		page.setList(list);

		Integer count = GroupDao.countGroup(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Group getGroupById(String GroupId) {
		return GroupDao.getGroupById(GroupId);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void addGroup(Group Group) {
		GroupDao.addGroup(Group);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void updateGroup(Group Group) {
		GroupDao.updateGroup(Group);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteGroupById(String GroupId) {
		GroupDao.deleteGroupById(GroupId);
	}
}
